<template>
  <div class="app-container">
    <h3>会员列表</h3>
    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="memberQuery.mobile" placeholder="手机号"/>
      </el-form-item>

      <el-form-item>
        <el-input v-model="memberQuery.nickname" placeholder="会员昵称"/>
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="initMemberList()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>

    </el-form>
    <!-- 列表显示-->
    <el-table
      :data="list"
      border
      fit
      highlight-current-row>

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (current - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="mobile" label="手机号"/>

      <el-table-column prop="nickname" label="昵称"/>

      <el-table-column label="头像">
        <template slot-scope="scope">
          <div class="pic">
            <img :src="scope.row.avatar" alt="scope.row.title" width="150px" height="100px">
          </div>
        </template>
      </el-table-column>

      <el-table-column label="状态">
        <template slot-scope="scope">
          {{scope.row.isDisabled===1?'已禁用':'未禁用'}}
        </template>
      </el-table-column>

      <el-table-column prop="createTime" label="创建时间"/>

      <el-table-column label="操作" width="300" align="center">
        <template slot-scope="scope">
          <el-button type="info" title="详情" size="mini" icon="el-icon-info" @click="getMemberById(scope.row.id)">
          </el-button>
          <router-link :to="'/member/update/'+scope.row.id">
            <el-button type="primary" title="修改" size="mini" icon="el-icon-edit"
            ></el-button>
          </router-link>
          <el-button type="danger" title="删除" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <el-pagination
      :current-page="current"
      :total="total"
      :page-size="limit"
      :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
      style="padding: 30px 0; text-align: center;"
      layout="sizes, prev, pager, next, jumper, ->, total, slot"
      @current-change="initMemberList"
      @size-change="changeLimit"
    />
    <!-- 会员详情表单 -->
    <el-dialog :visible.sync="memberFormVisible" title="订单详情">
      <el-form :model="memberForm" label-width="120px">
        <el-form-item label="会员ID">
          <el-input readonly v-model="memberForm.id"/>
        </el-form-item>
        <el-form-item label="微信openId">
          <el-input readonly v-model="memberForm.openid"/>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input readonly v-model="memberForm.mobile"/>
        </el-form-item>
        <el-form-item label="昵称">
          <el-input readonly v-model="memberForm.nickname"/>
        </el-form-item>
        <el-form-item label="头像">
<!--          <template slot-scope="scope">-->
<!--            <el-image :src="scope.row.avatar" :title="memberForm.nickname"-->
<!--                      style="width: 375px;height: 215px">-->
<!--            </el-image>-->
            <div class="pic">
              <img :src="memberForm.avatar" alt="scope.row.title" width="150px" height="100px">
            </div>
<!--          </template>-->
          <!--          <el-input v-model="orderForm.courseCover"/>-->

        </el-form-item>
        <el-form-item label="性别">
          <el-input readonly v-model="memberForm.sex"/>
        </el-form-item>
        <el-form-item label="年龄">
          <el-input readonly v-model="memberForm.age"/>
        </el-form-item>
        <!--<el-form-item label="会员昵称">
          <el-input readonly v-model="memberForm.nickname"/>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input readonly v-model="memberForm.mobile"/>
        </el-form-item>
        <el-form-item label="付款金额">
          <el-input readonly v-model="memberForm.totalFee"/>
        </el-form-item>-->
        <el-form-item label="状态">
          <el-input readonly v-model="memberForm.isDisabled===1?'已禁用':'未禁用'"/>
        </el-form-item>
        <el-form-item label="最后登录时间">
          <el-input readonly v-model="memberForm.lastLoginTime"/>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-input readonly v-model="memberForm.createTime"/>
        </el-form-item>
        <el-form-item label="更新时间">
          <el-input readonly v-model="memberForm.updateTime"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="memberFormVisible = false">确&nbsp;&nbsp;定</el-button>
        <!--<el-button type="primary" @click="saveOrUpdate">确 定</el-button>-->
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import member from "@/api/member";

  export default {
    name: "list",
    data() {
      return {
        memberQuery: {},//查询对象
        current: 1,//当前页
        limit: 5,//每页显示记录数
        total: 0,//总记录数
        list: [],//列表集合
        memberForm: {},//会员信息
        memberFormVisible: false,//表单是否显示
      }
    },
    created() {
      this.initMemberList(1)
      // console.log("***************", this.list)
    },
    methods: {
      //初始化会员列表
      initMemberList(current = 1) {
        this.current = current
        member.pageMemberList(this.current, this.limit, this.memberQuery)
          .then(response => {
            this.list = response.data.items
            this.total = response.data.total
            // console.log("===========", this.list)
          })
      },
      //清空
      resetData() {
        //清空表单数据
        this.memberQuery = {}
        //刷新列表
        this.initMemberList(1)
      },
      // 当页码发生改变的时候
      changeLimit(limit) {
        // console.log(limit)
        this.limit = limit
        this.initMemberList(1)
      },
      //根据id查询
      getMemberById(id) {
        this.memberFormVisible = true
        //调用方法查询用户信息
        member.getMemberById(id)
          .then(response => {
            this.memberForm = response.data.member
            // console.log("===========",this.memberForm.isDisabled)
          })
      },
      //删除用户
      removeDataById(id) {
        this.$confirm('此操作将删除该用户, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          member.removeMemberById(id)
            .then(response => {
              //提示
              this.$message({
                type: 'success',
                message: response.message
              });
              //刷新列表
              this.initMemberList(1)
            })
            .catch(response => {
              //提示
              this.$message({
                type: 'error',
                message: response.message
              });
              //刷新列表
              this.initMemberList(1)
            })

        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },

    }
  }
</script>

<style scoped>

</style>
